package com.example.doctorstation.POJOController;
import com.example.doctorstation.Config.MyResponse;
import com.example.doctorstation.Helper.StringHelper;
import com.example.doctorstation.POJOData.*;
import com.example.doctorstation.POJOMapper.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class PatientAdviceController {
    @Resource
    PatientAdviceMapper patientAdviceMapper;

    // 访问url：localhost:8888/patientadvice?PATIENTID=1
    @GetMapping(value="/patientadvice")
    public MyResponse getPatientAdvice(PatientAdvice advice) {
        try {
            // System.out.println(advice.getPATIENTID());
            return new MyResponse(patientAdviceMapper.getPatientAdvice(advice.getPATIENTID()), "已获取该病人的医嘱", "该病人没有医嘱");
        } catch (Throwable e) {
            e.printStackTrace();
            return MyResponse.error(e.getMessage());
        }
    }

    @PostMapping(value="/patientadvice")
    public MyResponse addPatientAdvice(@RequestBody PatientAdvice advice)
    {
        try {
            return new MyResponse(patientAdviceMapper.addPatientAdvice(advice), "已增加该病人的医嘱！", "增加医嘱失败");
        } catch (Throwable e) {
            e.printStackTrace();
            return MyResponse.error(e.getMessage());
        }
    }

    @PutMapping(value="/patientadvice")
    public MyResponse updatePatientAdviceStatus(@RequestBody PatientAdvice advice)
    {
        try {
            // System.out.println(advice.getPADVICE_ID() + "  " + advice.getPADVICE_STATUS());
            return new MyResponse(patientAdviceMapper.updatePatientAdviceStatus(advice.getPADVICE_ID(),advice.getPADVICE_STATUS()), "已更新医嘱状态", "更新医嘱状态失败");
        } catch (Throwable e) {
            e.printStackTrace();
            return MyResponse.error(e.getMessage());
        }
    }

}
